/**
 * lvl r0
 */

var LVL = window.LVL = {}


define([
'blacksmith/game',
'lvl/config',
'lvl/ui',
'lvl/arena',
'lvl/components',
'lvl/component',
'lvl/levitator',
'lvl/fan',
'lvl/power'
], function() {



LVL.view = BLACKSMITH.element(document.body, 'div', CONFIG.styleView)


GAME.CreateScene(LVL.view, CONFIG.arenaSize, CONFIG.viewWidth, CONFIG.viewHeight, -CONFIG.gravity)
GAME.shadows(true)




GAME.onMouseWheel = function(delta) {
    
    if (LVL.keyCtrl) {
        
        CONFIG.viewWidth += ~~(CONFIG.viewResize * delta)
        CONFIG.viewHeight += ~~(CONFIG.viewResize * delta)
        GAME.Renderer.setSize(CONFIG.viewWidth, CONFIG.viewHeight)
        
        print('view size: ' + CONFIG.viewWidth + ',' + CONFIG.viewHeight)
        
    } else {
        
        GAME.fanY(-delta * CONFIG.cameraSpeed * GAME.Camera.object.position.y * 0.01)
    
    }
}


GAME.onMouseDown = function(event) {
    
    if (GAME.Mouse.button === 1) {
        
        
        
    } else if (GAME.Mouse.button === 3) {
        
        LVL.lastMouseX = event.clientX
        LVL.lastMouseY = event.clientY
        
    }
}


GAME.onMouseMove = function(event) {
    
    if (GAME.Mouse.button === 3) {
        
        LVL.onMouseMove_delta = event.clientX - LVL.lastMouseX
        if (LVL.onMouseMove_delta < 0)
            LVL.onMouseMove_delta = -(LVL.onMouseMove_delta * LVL.onMouseMove_delta)
        else
            LVL.onMouseMove_delta = LVL.onMouseMove_delta * LVL.onMouseMove_delta
        
        GAME.panRight(LVL.onMouseMove_delta * Math.PI * CONFIG.cameraSpeed * 0.001)
        
        LVL.onMouseMove_delta = event.clientY - LVL.lastMouseY
        if (LVL.onMouseMove_delta < 0)
            LVL.onMouseMove_delta = LVL.onMouseMove_delta * LVL.onMouseMove_delta
        else
            LVL.onMouseMove_delta = -(LVL.onMouseMove_delta * LVL.onMouseMove_delta)
        
        GAME.panUp(LVL.onMouseMove_delta * Math.PI * CONFIG.cameraSpeed * 0.001)
        
        LVL.lastMouseX = event.clientX
        LVL.lastMouseY = event.clientY
        
    }
    
}


GAME.onKeyDown = function(key) {
    
    LVL.keyCtrl = (key === 18)
    
}


GAME.onKeyUp = function(key) {
    
    LVL.keyCtrl = (key !== 18)
    
}


LVL.Components.createImages()

LVL.arena = new LVL.Arena()
LVL.UI.init()


GAME.play(function() {
    
    
    
})




LVL.z = new LVL.Levitator()
LVL.z.add(new LVL.Power())
LVL.z.add(new LVL.Fan())
GAME.add(LVL.z)



})
